In [ ]:
# Import required libraries
import requests
import urllib
import json
from __future__ import division
import math
import time

In [ ]:
# set key
key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# set base url
base_url="https://api.propublica.org/congress/v1/"

# set url parameters
method="members/"
member_id = "A000360"
file_format = ".json"

#set headers
headers = {'X-API-Key': key}

# make request
r = requests.get(base_url+method+member_id+file_format, headers=headers)

# parse data for component nested dictionaries
data=(r.json())

bioKeys = data['results'][0]
bioListData = data['results']

roleKeys = data['results'][0]['roles'][0]
roleListData = data['results'][0]['roles']

committeeKeys = data['results'][0]['roles'][0]['committees'][0]

# export to csv
import csv
with open('bio.csv', 'w') as file:
    dict_writer = csv.DictWriter(file, bioKeys)
    dict_writer.writeheader()
    dict_writer.writerows(bioListData)
    
with open('roles.csv', 'w') as file:
    dict_writer = csv.DictWriter(file, roleKeys)
    dict_writer.writeheader()
    dict_writer.writerows(roleListData)

with open('committees.csv', 'w') as file:
    dict_writer = csv.DictWriter(file, committeeKeys)
    dict_writer.writeheader()
    for roleObject in roleListData:
        dict_writer.writerows(roleObject['committees'])

ProPublica Congress API - specific member with member list

https://propublica.github.io/congress-api-docs/?shell#get-a-specific-member


In [ ]:
# set key
key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# set base url
base_url="https://api.propublica.org/congress/v1/"

# set url parameters
method="members/"
member_id = "A000360"
file_format = ".json"

#set headers
headers = {'X-API-Key': key}

# create a list of Member IDs from https://www.congress.gov/help/field-values/member-bioguide-ids to run the API request on more than one ID
data = []
with open('memberid.txt') as file:
    for line in file:
        data.append(line.strip())
        
# make request, build list of results for each FEC ID
data = []
for member_id in data:
    r = requests.get(base_url+method+member_id+file_format, headers=headers)
    member = r.json()['results']
    data.append(member)
    time.sleep(3)

# tbd

In [ ]:
# set base url
base_url="http://www.opensecrets.org/api/"

#set parameters
params = {"apikey" :  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"method" : "memPFDprofile",
"cid" : "N00009888",
"year" : "2014",
"output" : "json"}

# make request
r = requests.get(base_url,params=params)

# parse data
data = (r.json())
legList = data['response']['legislator']
legKeys = data['response']['legislator'][0]['@attributes']

# export to csv
import csv
with open('leg.csv', 'w') as file:
    dict_writer = csv.DictWriter(file, legKeys)
    dict_writer.writeheader()
    for legObject in legList:
        dict_writer.writerow(legObject['@attributes'])

In [ ]:
#has OSID from Open Secrets and BioID from ProPublica

import requests
import urllib
import json
from __future__ import division
import math

base_url = 'https://www.govtrack.us/api/v2/person/400326'
id
r = requests.get(base_url)
data= r.json()
data